<?php
namespace Modules\Captcha\Controllers;

class IndexController extends \Phalcon\Mvc\Controller {
  public function indexAction() {
    $builder = (new \Gregwar\Captcha\CaptchaBuilder(null, new \Gregwar\Captcha\PhraseBuilder(4, '23456789')))
      -> build($this -> request -> getQuery('w', 'int', 150, true), $this -> request -> getQuery('h', 'int', 40, true));
    $output = $builder -> get();

    $this -> session -> set($this -> request -> getQuery('modules', 'string', '', true) . '_captcha', $builder -> getPhrase());

    return $this -> response -> setContentLength(strlen($output)) -> setContentType('image/png') -> setContent($output);
  }
}
